using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VVASAMP
    {
        public DataRow Convert2VASAMP(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryVASAMP(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["VAPMANDANT"] = " ".PadRight(2 ); 
         dwReturn["VAPKOLL"] = " ".PadRight(5 ); 
         dwReturn["VAPART"] = " ".PadRight(24 ); 
         dwReturn["VAPFARBE"] = " ".PadRight(10 ); 
         dwReturn["VAPFORMAT"] = " ".PadRight(2 ); 
         dwReturn["VAPETIKETT"] = " ".PadRight(8 ); 
         dwReturn["VAPSTATUS"] = " ".PadRight(1 ); 
         dwReturn["VAPENTW"] = " ".PadRight(8 ); 
         dwReturn["VAPBORDUER"] = " ".PadRight(3 ); 
         dwReturn["VAPURKOLL"] = " ".PadRight(5 ); 
         dwReturn["VAPGEW"] = " ".PadRight(0 ); 
         dwReturn["VAPSPERRDAT"] = " ".PadRight(0 ); 
         dwReturn["VAPBESTAND"] = " ".PadRight(1 ); 
         dwReturn["VAPSTUEKZ"] = " ".PadRight(1 ); 
         dwReturn["VAPKLISCHEE"] = " ".PadRight(4 ); 
         dwReturn["VAPGROE"] = " ".PadRight(7 ); 
         dwReturn["VAPFILLER"] = " ".PadRight(85 ); 
         dwReturn["VAPAENZL"] = " ".PadRight(0 ); 
         dwReturn["VAPAENB"] = " ".PadRight(8 ); 
         dwReturn["VAPAEND"] = " ".PadRight(0 ); 
         dwReturn["VAPNEUB"] = " ".PadRight(8 ); 
         dwReturn["VAPNEUD"] = " ".PadRight(0 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapVASAMP(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveVASAMP(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryVASAMP(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapVASAMP(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertVASAMP(dwLocal, ITXDBVERSION);
            }
            UpdateVASAMP(dwLocal);
        }
        public void InsertVASAMP(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO VASAMP(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryVASAMP(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM VASAMP WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM VASAMP  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "VASAMP";
            Return = Result;
            return Return;
        }
        public void DeleteVASAMP(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM VASAMP   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateVASAMP(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE VASAMP SET "
                    +"VAPMANDANT= :VAPMANDANT,"
                    +"VAPKOLL= :VAPKOLL,"
                    +"VAPART= :VAPART,"
                    +"VAPFARBE= :VAPFARBE,"
                    +"VAPFORMAT= :VAPFORMAT,"
                    +"VAPETIKETT= :VAPETIKETT,"
                    +"VAPSTATUS= :VAPSTATUS,"
                    +"VAPENTW= :VAPENTW,"
                    +"VAPBORDUER= :VAPBORDUER,"
                    +"VAPURKOLL= :VAPURKOLL,"
                    +"VAPGEW= :VAPGEW,"
                    +"VAPSPERRDAT= :VAPSPERRDAT,"
                    +"VAPBESTAND= :VAPBESTAND,"
                    +"VAPSTUEKZ= :VAPSTUEKZ,"
                    +"VAPKLISCHEE= :VAPKLISCHEE,"
                    +"VAPGROE= :VAPGROE,"
                    +"VAPFILLER= :VAPFILLER,"
                    +"VAPAENZL= :VAPAENZL,"
                    +"VAPAENB= :VAPAENB,"
                    +"VAPAEND= :VAPAEND,"
                    +"VAPNEUB= :VAPNEUB,"
                    +"VAPNEUD= :VAPNEUD,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("VAPMANDANT", OracleType.NVarChar).Value = dwData["VAPMANDANT"].ToString(); 
          or1.Parameters.Add("VAPKOLL", OracleType.NVarChar).Value = dwData["VAPKOLL"].ToString(); 
          or1.Parameters.Add("VAPART", OracleType.NVarChar).Value = dwData["VAPART"].ToString(); 
          or1.Parameters.Add("VAPFARBE", OracleType.NVarChar).Value = dwData["VAPFARBE"].ToString(); 
          or1.Parameters.Add("VAPFORMAT", OracleType.NVarChar).Value = dwData["VAPFORMAT"].ToString(); 
          or1.Parameters.Add("VAPETIKETT", OracleType.NVarChar).Value = dwData["VAPETIKETT"].ToString(); 
          or1.Parameters.Add("VAPSTATUS", OracleType.NVarChar).Value = dwData["VAPSTATUS"].ToString(); 
          or1.Parameters.Add("VAPENTW", OracleType.NVarChar).Value = dwData["VAPENTW"].ToString(); 
          or1.Parameters.Add("VAPBORDUER", OracleType.NVarChar).Value = dwData["VAPBORDUER"].ToString(); 
          or1.Parameters.Add("VAPURKOLL", OracleType.NVarChar).Value = dwData["VAPURKOLL"].ToString(); 
          or1.Parameters.Add("VAPGEW", OracleType.NVarChar).Value = dwData["VAPGEW"].ToString(); 
          or1.Parameters.Add("VAPSPERRDAT", OracleType.NVarChar).Value = dwData["VAPSPERRDAT"].ToString(); 
          or1.Parameters.Add("VAPBESTAND", OracleType.NVarChar).Value = dwData["VAPBESTAND"].ToString(); 
          or1.Parameters.Add("VAPSTUEKZ", OracleType.NVarChar).Value = dwData["VAPSTUEKZ"].ToString(); 
          or1.Parameters.Add("VAPKLISCHEE", OracleType.NVarChar).Value = dwData["VAPKLISCHEE"].ToString(); 
          or1.Parameters.Add("VAPGROE", OracleType.NVarChar).Value = dwData["VAPGROE"].ToString(); 
          or1.Parameters.Add("VAPFILLER", OracleType.NVarChar).Value = dwData["VAPFILLER"].ToString(); 
          or1.Parameters.Add("VAPAENZL", OracleType.NVarChar).Value = dwData["VAPAENZL"].ToString(); 
          or1.Parameters.Add("VAPAENB", OracleType.NVarChar).Value = dwData["VAPAENB"].ToString(); 
          or1.Parameters.Add("VAPAEND", OracleType.NVarChar).Value = dwData["VAPAEND"].ToString(); 
          or1.Parameters.Add("VAPNEUB", OracleType.NVarChar).Value = dwData["VAPNEUB"].ToString(); 
          or1.Parameters.Add("VAPNEUD", OracleType.NVarChar).Value = dwData["VAPNEUD"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
